package com.bdth.bdthmall.api.epoint.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.bdth.bdthmall.api.annotation.AuthToken;
import com.bdth.bdthmall.api.epoint.vo.*;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2020/1/13.
 */
@RestController
@RequestMapping("/ecservice")
public class ProductController {
    @RequestMapping(value = "/getProductPool", method = RequestMethod.POST)
    @AuthToken
    public ResponseProductPoolVo getProductPool(@RequestParam String data){
        JSONObject json = JSONObject.parseObject(data);
        String categoryId = json.getString("categoryId");
        System.out.println("categoryId:"+categoryId);
        List<String > list = new ArrayList<>();
        list.add("7012");
        list.add("7011");
        return ResponseProductPoolVo.builder().success(true).msg("数据返回成功！").sku(list);
    }

    @RequestMapping(value = "/getProductDetail", method = RequestMethod.POST)
    @AuthToken
    public ResponseProductDetailVo getProductDetail(@RequestParam String data){
        JSONObject json = JSONObject.parseObject(data);
        String sku = json.getString("sku");
        System.out.println("sku:"+sku);
        Map<String,String > param = new HashMap<>();
        param.put("品牌","浪潮（INSPUR）");
        param.put("型号","四颗4830V4 14核2.0G CPU 四电源");

        ResponseProductDetailVo detailVo = new ResponseProductDetailVo();
        detailVo.setIsSuccess(true);
        detailVo.setReturnMsg("返回数据详情成功");
        detailVo.setSku("7012");
        detailVo.setWeight("13.000");
        detailVo.setImage("http://www.youqi24.com/images/201708/goods_img/7012_G_1502995253566.jpg");
        detailVo.setState(1);
        detailVo.setBrand("浪潮（INSPUR）");
        detailVo.setModel("四颗4830V4 14核2.0G CPU 四电源");
        detailVo.setName("浪潮  机架服务器 2.5英寸小");
        detailVo.setIntroduction("<p>&nbsp;<img src=\\\"http://www.youqi24.com/images/upload/Image/1(15).png\\\" width=\\\"750\\\" height=\\\"459\\\" alt=\\\"\\\" /><img src=\\\"http://www.youqi24.com/images/upload/Image/2(14).jpg\\\" width=\\\"750\\\" height=\\\"1266\\\" alt=\\\"\\\" /><img src=\\\"http://www.youqi24.com/images/upload/Image/3(12).jpg\\\" width=\\\"750\\\" height=\\\"1235\\\" alt=\\\"\\\" /><img src=\\\"http://www.youqi24.com/images/upload/Image/4(11).jpg\\\" width=\\\"750\\\" height=\\\"1219\\\" alt=\\\"\\\" /><img src=\\\"http://www.youqi24.com/images/upload/Image/5(7).jpg\\\" width=\\\"750\\\" height=\\\"933\\\" alt=\\\"\\\" /><img src=\\\"http://www.youqi24.com/images/upload/Image/6(6).jpg\\\" alt=\\\"\\\" /><img src=\\\"http://www.youqi24.com/images/upload/Image/7(7).jpg\\\" width=\\\"750\\\" height=\\\"882\\\" alt=\\\"\\\" /></p>");
        detailVo.setCategory("A02010103");
        detailVo.setParam(param);
        detailVo.setSaleUnit("");
        detailVo.setIsProtected(0);

        return detailVo;
    }

    @RequestMapping(value = "/getProductReview", method = RequestMethod.POST)
    @AuthToken
    public ResponseProductReviewVo getProductReview(@RequestParam String data) {
        JSONObject json = JSONObject.parseObject(data);
        String skuIdStr = json.getString("skuId");
        List<String> skuId = JSONObject.parseArray(skuIdStr,String.class);
        for(String sku:skuId) {
            System.out.println("sku:"+sku);
        }
        ResponseProductReviewVo reviewVo = new ResponseProductReviewVo();
        reviewVo.setIsSuccess(true);
        reviewVo.setReturnMsg("商品评价");
        List<ProductReviewVo> list = new ArrayList<>();
        ProductReviewVo p1 = new ProductReviewVo();
        p1.setSkuId("7012");
        p1.setAverageScore(3.3f);
        p1.setGeneralRate(3.4f);
        p1.setGoodRate(4.5f);
        p1.setPoorRate(3.0f);
        list.add(p1);
        ProductReviewVo p2 = new ProductReviewVo();
        p2.setSkuId("7013");
        p2.setAverageScore(3.3f);
        p2.setGeneralRate(3.4f);
        p2.setGoodRate(4.5f);
        p2.setPoorRate(3.0f);
        list.add(p2);
        reviewVo.setProductReview(list);
        return  reviewVo;
    }

    @RequestMapping(value = "/getProductImage", method = RequestMethod.POST)
    @AuthToken
    public ResponseProductImageVo getProductImage(@RequestParam String data) {
        JSONObject json = JSONObject.parseObject(data);
        String skuIdStr = json.getString("sku");
        List<String> skuId = JSONObject.parseArray(skuIdStr,String.class);
        for(String sku:skuId) {
            System.out.println("sku:"+sku);
        }

        ResponseProductImageVo imageVo = new ResponseProductImageVo();
        imageVo.setIsSuccess(true);
        imageVo.setReturnMsg("商品图片接口");

        List<ProductImageVo> imageVosList = new ArrayList<>();
        List<ProductImageUrlVo> imageUrlVos = new ArrayList<>();
        ProductImageUrlVo url1 = new ProductImageUrlVo("http://www.youqi24.com/images/201706/thumb_img/5996_thumb_G_1496942014752.jpg",1);
        imageUrlVos.add(url1);
        ProductImageUrlVo url2 = new ProductImageUrlVo("http://www.youqi24.com/images/201706/goods_img/5996_G_1496942014421.jpg",0);
        imageUrlVos.add(url2);
        ProductImageVo imageVo1 = new ProductImageVo("7012",imageUrlVos);
        imageVosList.add(imageVo1);

        List<ProductImageUrlVo> imageUrlVos2 = new ArrayList<>();
        ProductImageUrlVo url3 = new ProductImageUrlVo("http://www.youqi24.com/images/201806/thumb_img/5996_thumb_G_1496942014752.jpg",1);
        imageUrlVos2.add(url3);
        ProductImageUrlVo url4 = new ProductImageUrlVo("http://www.youqi24.com/images/201806/goods_img/5996_G_1496942014421.jpg",0);
        imageUrlVos2.add(url4);
        ProductImageVo imageVo2 = new ProductImageVo("7013",imageUrlVos2);
        imageVosList.add(imageVo2);

        imageVo.setResult(imageVosList);
        return imageVo;
    }

    @RequestMapping(value = "/getProductOnShelvesInfo", method = RequestMethod.POST)
    @AuthToken
    public ResponseProductOnShelvesVo getProductOnShelvesInfo(@RequestParam String data) {
        JSONObject json = JSONObject.parseObject(data);
        String skuIdStr = json.getString("sku");
        List<String> skuId = JSONObject.parseArray(skuIdStr,String.class);
        for(String sku:skuId) {
            System.out.println("sku:"+sku);
        }
        List<ProductOnShelvesVo> list = new ArrayList<>();
        ProductOnShelvesVo ps1 = new ProductOnShelvesVo("7012",1);
        list.add(ps1);
        ProductOnShelvesVo ps2 = new ProductOnShelvesVo("7013",0);
        list.add(ps2);
        ResponseProductOnShelvesVo productOnShelvesVo = new ResponseProductOnShelvesVo();
        productOnShelvesVo.setIsSuccess(true);
        productOnShelvesVo.setReturnMsg("商品上下架状态查询");
        productOnShelvesVo.setOnShelvesList(list);
        return  productOnShelvesVo;
    }

    @RequestMapping(value = "/getProductInfoFromEC", method = RequestMethod.POST)
    @AuthToken
    public ResponseProductInfoFromECVo getProductInfoFromEC(@RequestParam String data) {
        JSONObject json = JSONObject.parseObject(data);
        ResponseProductInfoFromECVo infoFromECVo = new ResponseProductInfoFromECVo();
        infoFromECVo.setIsSuccess(true);
        infoFromECVo.setReturnMsg("商品映射关系查询");
        List<ProductInfoFromECVo> list = new ArrayList<>();
        ProductInfoFromECVo ecVo1 = new ProductInfoFromECVo();
        ecVo1.setProductId("商品编码(新点)");
        ecVo1.setProductName("商品名称（新点）");
        ecVo1.setProductUrl("商品参考链接（新点）");
        ecVo1.setProductUrlEC("商品参考链接（电商）");
        ecVo1.setProductNameEC("商品名称（电商）");
        ecVo1.setSkuId("商品编码（电商）");
        list.add(ecVo1);

        ProductInfoFromECVo ecVo2 = new ProductInfoFromECVo();
        ecVo2.setProductId("497cf175-f908-4dc6-bcd8-1a1518127449");
        ecVo2.setProductName("联想（Lenovo）M7206 激光一体机+墨粉");
        ecVo2.setProductUrl("http://211.90.38.212:8080/Mall/HeBei/detail.aspx?product_id=497cf175-f908-4dc6-bcd8-1a1518127449");
        ecVo2.setProductUrlEC("http://www.youqi24.com/goods.php?id=6141");
        ecVo2.setProductNameEC("联想（Lenovo）M7206 黑白激光多功能一体机");
        ecVo2.setSkuId("6141");
        list.add(ecVo2);
        infoFromECVo.setProductInfoList(list);
        return infoFromECVo;
    }

    @RequestMapping(value = "/queryCountPrice", method = RequestMethod.POST)
    @AuthToken
    public ResponseCountPriceVo queryCountPrice(@RequestParam String data) {
        JSONObject json = JSONObject.parseObject(data);
        String skuIdStr = json.getString("sku");
        String cityId = json.getString("cityId");
        System.out.println("cityId:"+cityId);
        List<String> skuId = JSONObject.parseArray(skuIdStr,String.class);
        for(String sku:skuId) {
            System.out.println("sku:"+sku);
        }
        ResponseCountPriceVo countPriceVo = new ResponseCountPriceVo();
        countPriceVo.setIsSuccess(true);
        countPriceVo.setReturnMsg("商品折扣价格");
        countPriceVo.setCityId(cityId);
        List<CountPriceVo> list = new ArrayList<>();
        CountPriceVo priceVo1 = new CountPriceVo("7012","149624.05","0.95");
        CountPriceVo priceVo2 = new CountPriceVo("7013","49624.05","0.98");
        list.add(priceVo1);
        list.add(priceVo2);
        countPriceVo.setPriceList(list);
        return countPriceVo;
    }
}
